package com.example.luckypan;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;

import com.example.lunckypanlib.view.LunckyPan;

public class MainActivity extends AppCompatActivity {

    private LunckyPan lunckyPan;
    private int select = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        lunckyPan = findViewById(R.id.pan);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("靠天吃饭");//设置主标题
        toolbar.inflateMenu(R.menu.activity_tool_bar);//设置右上角的填充菜单
        //点击事件
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                lunckyPan.luckyEnd();
                switch (item.getItemId()) {
                    case R.id.random:
                        select = -1;
                        break;
                    case R.id.bingge:
                        select = 0;
                        break;
                }
                return true;
            }
        });

    }

    public void startPan(View v) {
        lunckyPan.luckyStart(select);
    }

    public void endPan(View v) {
        lunckyPan.luckyEnd();
    }
}
